package com.itheima;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.io.IOException;

@WebServlet( "/Servlet")
public class Servlet extends HttpServlet {
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
       String username = req.getParameter("username");
        String password = req.getParameter("password");
        Cookie cookie01= new Cookie("username",username);
        Cookie cookie02 = new Cookie("password",password);
        resp.addCookie(cookie01);
        resp.addCookie(cookie02);
        Cookie[] cookies = req.getCookies();
        for (Cookie cookie : cookies) {
            System.out.println(cookie);
        }
        HttpSession session = req.getSession();
        System.out.println(session);

    }

    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
